<!DOCTYPE HTML>
<html>
<head>
    <title>Error</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="/scripts/jquery.min.js"></script>
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <script src="/scripts/miniui/miniui.js"></script>
</head>
<body>
<div id="form1" style="margin: 0 auto">
    <span style="width:80px;display:inline-block;">用户名称：</span>
    <input id="name" class="mini-textbox" style="width:155px;" />

    <span style="width:80px;display:inline-block;">用户状态：</span>
    <input id="status" class="mini-combobox" style="width:155px;" data="userStatus"/>
    <br/><br/>

    <span style="width:80px;display:inline-block;">身份证号码：</span>
    <input id="idCard"  onblur="checkIdCard" class="mini-textbox"   style="width:155px;" />

    <span style="width:80px;display:inline-block;">用户级别：</span>
    <input id="level" class="mini-combobox" style="width:155px;" data="<%= result%>"  />

    <br/><br/>

    <span style="width:80px;display:inline-block;">微信号：</span>
    <input id="weChat" class="mini-textbox" style="width:155px;"/>

    <span style="width:80px;display:inline-block;">电话号码：</span>
    <input id="telephone" class="mini-textbox" style="width:155px;"/>

    <br/><br/>

    <span style="width:80px;display:inline-block;">团队长：</span>
    <input id="teamLeader" class="mini-textbox" style="width:155px;"/>

    <br/><br/>

    <span style="width:120px;display:inline-block;">授权开始时间：</span>
    <input id="startPowerTime" class="mini-datepicker" style="width:200px;"  nullValue="null"
           format="yyyy-MM-dd H:mm:ss" timeFormat="H:mm:ss" showTime="true" showOkButton="true" showClearButton="false"/>

    <br /><br />

    <span style="width:120px;display:inline-block;">授权结束时间：</span>
    <input id="endPowerTime" class="mini-datepicker" style="width:200px;"  nullValue="null"
           format="yyyy-MM-dd H:mm:ss" timeFormat="H:mm:ss" showTime="true" showOkButton="true" showClearButton="false"/>

    <br /><br />

    <div style="margin: 0 auto;text-align: center">
        <a class="mini-button " iconCls="icon-ok" onclick="updataShop()">确定</a>
        <a class="mini-button" iconCls="icon-cancel" onclick="onCancel">取消</a>
    </div>
</div>
</body>
<script>
    var userStatus = [{ id: 1, text: '正常' }, { id: 0, text: '关闭'}];
    var flag =true;
    function updataShop() {
        console.log("上传");
        var name = mini.get("name").getValue();
        var status = mini.get("status").getValue();
        var idCard = mini.get("idCard").getValue();
        var level = mini.get("level").getValue();
        var levelName = mini.get("level").getText();
        var weChat = mini.get("weChat").getValue();
        var telephone = mini.get("telephone").getValue();
        var startPowerTime = mini.get("startPowerTime").getValue();
        var endPowerTime = mini.get("endPowerTime").getValue();
        var teamLeader = mini.get("teamLeader").getValue();
        var form = new mini.Form("#form1");
        if (flag == false){
            return
        }
        console.log("上传2");
        $.ajax({
            type: "POST",
            url: "/getdata/addUserInformation",
            data: {
                name: name,
                status: status,
                idCard: idCard,
                level: level,
                weChat: weChat,
                telephone:telephone,
                startPowerTime:startPowerTime,
                endPowerTime:endPowerTime,
                teamLeader:teamLeader,
                levelName:levelName,
            },
            beforeSend:function(){
                form.loading();
            },
            success: function (result) {
                if (result=='10000'){
                    console.log("成功");
                    CloseWindow("save")
                }else {
                    alert('生成证书失败');
                    CloseWindow("save")
                };
            }
        })
    }
    //    关闭窗口
    function CloseWindow(action) {
        if (action == "close" && form.isChanged()) {
            if (confirm("数据被修改了，是否先保存？")) {
                return false;
            }
        }
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();
    }
    function onOk(e) {
        SaveData();
    }
    function onCancel(e) {
        CloseWindow("cancel");
    }
    function checkIdCard(e) {
        var idCard = mini.get("idCard").getValue();
        idCard=idCard.replace(/(^\s*)|(\s*$)/g, '');
        $.ajax({
            type: "POST",
            url: "/getdata/auth/idCardVer",
            data: {
                idCard: idCard,
            },
            success: function (result) {
                result = JSON.parse(result);
                if (result.total>0){
                    mini.get("idCard").setIsValid(false);
                    flag = false
                }else{
                    flag =true
                };
            }
        })
    }

</script>
</html>